#include "exceptions.h"


gate_desc64 *get_idt64(void)
{
	struct desc_ptr idtd;
  store_idt(&idtd);
  
  return (gate_desc64 *) idtd.address;
}



void set_idt64 (gate_desc64 *idt)
{
  struct desc_ptr idtr = make_test_idtr (idt);
  load_idt(&idtr);
}


struct desc_ptr make_test_idtr (gate_desc64 *idt) {
	struct desc_ptr tmp;
  tmp.address = (u64)idt;
  tmp.size = 256*sizeof(gate_desc64) - 1;
  
  return tmp;
}



void set_int64(gate_desc64 *idt, int interrupt, u64 addr)
{
  pack_gate64(&(idt[interrupt]), GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
}


void init_test_idt64 (gate_desc64 *idt, u64 handlers, u64 handler_size)
{
	int i;
	gate_desc64 *desc;
	u64 h = handlers;
	
	for (i = 0, desc = idt; i < 256; ++i, ++desc, h += handler_size)
		set_int64(idt, i, h);
}
